package zhihuilan.controlle.wechatMini;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import zhihuilan.common.WxMiniResponse;
import zhihuilan.common.enums.ResultEnum;
import zhihuilan.common.utils.WechatPayUtils;
import zhihuilan.config.WeChatPayMiniConfig;
import zhihuilan.controlle.BasicController;
import zhihuilan.params.query.MyPayOrderQueryParam;
import zhihuilan.service.MyPayOrderService;

@Slf4j
@RestController
@RequestMapping("/app/Pay")
public class MyPayOrderController extends BasicController {

    @Autowired
    private MyPayOrderService myPayOrderService;

    /**
     * @api {GET} /Pay/xcxgetPrepayId 获取订单id
     * @apiParam {string}  guid 登录标识
     * @apiParam {int}  goodsid 商品id
     * @apiParam {int}  type 1厂家 2市场
     * @apiParam {string}  title 商品名
     * @apiParam {int}  amount 价格
     * @apiParam {string}  platform  平台
     */
    @PostMapping("/xcxgetPrepayId")
    public WxMiniResponse xcxGetPrepayId(@RequestBody MyPayOrderQueryParam myPayOrderQueryParam){
        System.out.println(myPayOrderQueryParam);
        if (!isCheckLogin(myPayOrderQueryParam.getGuid())) {
            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        myPayOrderQueryParam.setCreateUser(currentStaff.getId()+"");
        String PrepayId = myPayOrderService.xcxgetPrepayId(myPayOrderQueryParam);
        return WxMiniResponse.ok(PrepayId);
   }

    /**
     * @api paycallback 支付通知
     * @apiParam {string}  guid 登录标识
     * @apiParam {int}  order 订单id
     * @apiParam {int}  type 1厂家 2市场
     * @apiParam {string}  id 厂家id/市场id
     */
    @PostMapping("/paycallback")
    public WxMiniResponse paycallback(@RequestBody MyPayOrderQueryParam myPayOrderQueryParam){
        if (!isCheckLogin(myPayOrderQueryParam.getGuid())) {
            //如果用户未登陆，提示用户未登陆信息，并且返回未登陆的枚举编码；
            return WxMiniResponse.error(ResultEnum.UNLOGIN.getKey(), ResultEnum.UNLOGIN.getValue());
        }
        myPayOrderQueryParam.setCreateUser(currentStaff.getId()+"");
        String PrepayId = myPayOrderService.xcxgetPrepayId(myPayOrderQueryParam);
        return WxMiniResponse.ok(PrepayId);
    }



}
